import com.google.common.base.Splitter;
import com.google.common.io.Resources;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Created by chenxin34 on 2021/1/25 下午3:53.
 */
public class MatrixUtil {
    public static void main(String[] args) throws Exception {
        //hive表矩阵行，也就是骑手
        String rowStr = "21625160,3435574,5933148,16331006,17399553,18447121,7742079,19762976,20474677,21669189,9955973,21019477,17562908,13603032,14695671,8549019,21850452,21789520,8136802,4819050,7374932,8567975,12652776,16031966,19885315,7274562,14925516,11565698,21517180,16090317,17547058,21727602,20877060,21308793,6367324,12799107,5939226,16533180,21601544,3997310,19778415,14672541,20603262,18319698,3047016,19254125,10646763,20365183,20845941,19051375,21800705,3649656,19427687,21624089,6033932,3062398,6218759,21600552,12958887,21518636,6553600,13136558,20192606,21408043,18897741,16682641,18038627,21554488,5191740,19184983,20943692,2880095,7696908,2417247,13850799,18047854,21576503,17790320,11753164,20720451,17980781,12483134,16644220,18733470,6938858,21566412,15948917,20237758,8133367,21850566,20251577,5716696,20472247,21682136,18844556,21179349,9093650,20357038,3930786,16099950,10397189,3779234,21239769,15748206,21033952,5129454,20351891,19579788,15830614,11953694,4293355,20384154,12125207,16738384,21669370,14868051,16414286,21230070,21812730,12566537,21681660,16580164,21577712,21871607,16315459,20057486,5226639,9378893,21296512,6348453,17289154,9119309,20140021,18940390,21295501,18573778,14620182,14812713,17393092,21120399,16293942,14996022,18541512,14117888,12164707,20244974,19842037,15769132,16109608,21696405,15204406,18805244,9687671,10389114,10768961,20395986,17313263,19315662,11904095,16371221,18126840,3740373,18648561,2962141,15055892,21789118,10140770,13049407,20336590,4910771,3394249,7022743,21752247,18398182,16510970,21902415,2986286,5155146,12029361,5662033,4176184,7960945,19052585,21621317,12338609,21770818,21578844,20502062,3658029,11565487,13754866,5875582,20932630,21100648,4503401,18865200,8905139,21445233,7245144,17705529,21110906,8252231,18031145,3126036,15008217,20840961,9360846,19895918,21780494,17500739,7409976,14597010,20573812,21260810,18540628,19890815,18435144,3669350,12164584,21824024,7426852,21541918,11944928,10102732,4196118,3651425,12192237,12872604,18531395,21373979,4577560,21490202,20175469,21623318,5336880,16908899,12175835,15385993,14346169,21717037,20158037,16803943,14723464,21827108,19486275,17322594,18889292,3231070,21554232,20489801,21137457,21658686,19077206,20232258,6599965,10054628,6703899,17259137,17527948,19139756,21669059,4381643,6950880,14125404,18132122,10423569,3114913,21323989,15834980,6925822,21740242,21859564,11761426,12164891,6034425,21264622,7164871,21585639,11618079,19224714,19273353,10912532,10323243,12946802,11529495,21881073,9020724,20528772,17919150,4260862,5437846,21668993,19148520,18343128,21122197,12172640,18011340,16040746,13872432,6637446,21847721,7487386,14446901,20451027,5384633,19825349,18436343,5522874,20953295,19349206,7000984,10692432,10601817,21879991,21693104,6083495,21715639,15787788,7637897,8915319,21351098";
        List<String> riderIdsString = Splitter.on(",").omitEmptyStrings().splitToList(rowStr);
        int driverIndex = riderIdsString.indexOf("17313263");
        System.out.println("driverIndex: " + driverIndex);
        //hive表矩阵列，也就是单
        String colStr = "1611466981669161258,1611466968651161662,1611466974867161647,1611466858762161791,1611466962867161784,1611466994762161051,1611466966783161340,1611466329616161908,1611466956844161120,1611466948765161818\t";
        List<String> waybillIdsString = Splitter.on(",").omitEmptyStrings().splitToList(colStr);
        int waybillIndex = waybillIdsString.indexOf("1611466956844161120");
        System.out.println("waybillIndex: " + waybillIndex);
        System.out.println("column size: " + waybillIdsString.size());
        int colSize = waybillIdsString.size();
        //hive表矩阵内容，由于数据量太大要读文件
        String matrix = Resources.toString(Resources.getResource("bytes.txt"), Charset.defaultCharset());
        List<String> matrixValueString = Splitter.on(",").omitEmptyStrings().splitToList(matrix);
        //计算index得到单和骑手匹配的过滤码
        String driverWaybillValue = matrixValueString.get(driverIndex * colSize + waybillIndex);
        System.out.println("driverWaybillValue: " + driverWaybillValue);
        //计算这个骑手与所有单匹配的过滤码
        List<String> thisDriverAllWaybillValue = new ArrayList<>();
        for (int i = driverIndex * colSize; i < (driverIndex + 1) * colSize; i++) {
            thisDriverAllWaybillValue.add(matrixValueString.get(i));
        }
        System.out.println("thisDriverAllWaybillValue " + thisDriverAllWaybillValue);
    }
}
